package top.ztf.erp.visitors;

import top.ztf.erp.dao.PermissionDao;
import top.ztf.erp.domain.PermissionNode;

import java.util.List;

public abstract class VisitorTemplate implements Visitor{

    protected final PermissionDao permissionDao;

    public VisitorTemplate(PermissionDao permissionDao) {
        this.permissionDao = permissionDao;
    }
    //共同的逻辑
    @Override
    public final void visitCheckPermissionNode(PermissionNode permissionNode){
        List<PermissionNode> childPermission = permissionDao.getChildPermission(permissionNode.getId());

        if (childPermission != null && childPermission.size()>0){
            childPermission.forEach(t->t.accept(this));
        }
        doCHeckPermissionNode(permissionNode);
    }

    //子类 的业务逻辑必须由自己实现
    public abstract void doCHeckPermissionNode(PermissionNode permissionNode);


    @Override
    public void visitCheckRole(String array) {
    }

}
